package com.study.all;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>添加类描述</p>
 *
 * @author chentao
 * @version v 0.1 2022/8/31 19:04
 */
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
    public static final String shortFormat = "yyyyMMdd";
    public static final String longFormat = "yyyyMMddHHmmss";
    public static final String webFormat = "yyyy-MM-dd";
    public static final String timeFormat = "HHmmss";
    public static final String monthFormat = "yyyyMM";
    public static final String chineseDtFormat = "yyyy年MM月dd日";
    public static final String newFormat = "yyyy-MM-dd HH:mm:ss";
    public static final String noSecondFormat = "yyyy-MM-dd HH:mm";

    /**
     * 加减天数
     *
     * @param date
     * @param amount
     * @return
     */
    public static Date addDate(Date date, Integer amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_MONTH, amount);
        return cal.getTime();
    }

    /**
     * 加减分钟
     *
     * @param date
     * @param amount
     * @return
     */
    public static Date addMinute(Date date, Integer amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.MINUTE, amount);
        return cal.getTime();
    }

    public static String format(Date date, String format) {
        return date == null ? null : (new SimpleDateFormat(format)).format(date);
    }

    public static Date parse(String date, String format) throws ParseException {
        return date == null ? null : (new SimpleDateFormat(format)).parse(date);
    }
}
